import {reqBrandList} from '@/api';
import { reqSizeList } from '@/api';
import { reqColorList } from '@/api';
import {reqTypeList} from '@/api';
import {reqShoesList} from '@/api';
import { reqShoesListByBrands } from '@/api';
const state = {
    brandList: [],
    sizeList: [],
    colorList: [],
    typeList: [],
    shoesByBrand: [],
    shoesList: {}
};

const mutations = {
    GETBRANDLIST(state, brandList) {
        state.brandList = brandList
    },
    GETSIZELIST(state, sizeList) {
        state.sizeList = sizeList
    },
    GETCOLORLIST(state, colorList) {
        state.colorList = colorList
    },
    GETTYPELIST(state, typeList) {
        state.typeList = typeList
    },
    GETSHOESLIST(state, shoesList) {
        state.shoesList = shoesList
    },
    GETSHOESBYBRAND(state, shoesByBrand) {
        state.shoesByBrand = shoesByBrand
    }
};

const actions = {
    // 获取品牌信息
    async getBrandList({commit}) {
        let result = await reqBrandList();
        if(result.code == 200) {
            commit('GETBRANDLIST',result.data);
        }
    },
    // 获取尺码信息
    async getSizeList({commit}) {
        let result = await reqSizeList();
        if(result.code == 200) {
            commit('GETSIZELIST',result.data.size);
        }
    },
    // 获取前台展示的商品信息
    async getColorList({commit}) {
        let result = await reqColorList();
        if(result.code == 200) {
            commit('GETCOLORLIST',result.data.color);
        }
    },
    // 获取鞋子版型
    async getTypeList({commit}) {
        let result = await reqTypeList();
        if(result.code == 200) {
            commit('GETTYPELIST',result.data);
        }
    },
    // 获取鞋子数据
    async getShoesList({commit},searchParams) {
        let result = await reqShoesList(searchParams);
        console.log(result.data);
        if(result.code == 200) {
            commit('GETSHOESLIST',result.data.shoes);
        }
    },
    // 根据品牌名获取鞋子数据
    async getShoesListByBrands({commit},bid) {
        let result = await reqShoesListByBrands(bid);
        if(result.code == 200) {
            commit('GETSHOESBYBRAND',result.data);
        }
    }
};

const getters = {
    shoesList(state) {
        return state.shoesList.result
    }
    // shoesBrandsList(state) {
    //     return state.shoesList.brands
    // },
    // shoesColorList(state) {
    //     return state.shoesList.color
    // },
    // shoesPhotos(state) {
    //     return state.shoesList.shoePhotos
    // }

};

export default {
    state,
    mutations,
    actions,
    getters
}